package system.model.converter;

import common.model.po.SysUser;
import common.model.request.RegisterRequest;
import system.model.request.SaveUserRequest;
import system.model.vo.UserInfo;

/**
 * 在此填写类的用途、注意事项等
 *
 * @author 米泽鹏
 * @since 2021-08-08 下午 8:41
 */
public class SysUserConverter {

	public static SysUser saveRequestToPo(SaveUserRequest saveUserRequest) {
		if (saveUserRequest == null) {
			return null;
		}
		SysUser sysUser = new SysUser();
		sysUser.setNickname(saveUserRequest.getNickname());
		sysUser.setUsername(saveUserRequest.getUsername());
		sysUser.setPassword(saveUserRequest.getPassword());
		sysUser.setValid(saveUserRequest.getValid());
		sysUser.setAvatar(saveUserRequest.getAvatar());
		sysUser.setGender(saveUserRequest.getGender());
		sysUser.setEmail(saveUserRequest.getEmail());
		sysUser.setEmailValid(saveUserRequest.getEmailValid());
		sysUser.setEmailNotifyTypes(saveUserRequest.getEmailNotifyTypes());
		sysUser.setIntroduction(saveUserRequest.getIntroduction());
		sysUser.setId(saveUserRequest.getId());
		return sysUser;
	}

	public static SysUser registerRequestToPo(RegisterRequest registerRequest) {
		if (registerRequest == null) {
			return null;
		}
		SysUser sysUser = new SysUser();
		sysUser.setNickname(registerRequest.getNickname());
		sysUser.setUsername(registerRequest.getUsername());
		sysUser.setPassword(registerRequest.getPassword());
		sysUser.setEmail(registerRequest.getEmail());
		sysUser.setAvatar(registerRequest.getAvatar());
		sysUser.setGender(registerRequest.getGender());
		sysUser.setIntroduction(registerRequest.getIntroduction());
		return sysUser;
	}

	public static UserInfo poToUserInfo(SysUser sysUser) {
		if (sysUser == null) {
			return null;
		}
		UserInfo userInfo = new UserInfo();
		userInfo.setUserId(sysUser.getId());
		userInfo.setNickname(sysUser.getNickname());
		userInfo.setUsername(sysUser.getUsername());
		userInfo.setGender(sysUser.getGender());
		userInfo.setAvatar(sysUser.getAvatar());
		userInfo.setIntroduction(sysUser.getIntroduction());
		return userInfo;
	}

}
